﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;

namespace ExFlash.Records
{
    [TypeConverter(typeof(CollectionConverter))]
    public class FillStyleArray : ISwfSerializable, IList<FillStyleRecord>, IList
    {
        private readonly ShapeType _shapeType;
        
        public ushort FillStyleCount
        {
            get;
            private set;
        }

        public List<FillStyleRecord> FillStyles
        {
            get;
            private set;
        }

        public FillStyleArray(ShapeType type)
        {
            _shapeType = type;
        }
        
        #region ISwfSerializable Members

        public void SwfDeserialize(BinaryBitReader reader)
        {
            FillStyleCount = reader.ReadByte();

            if ((FillStyleCount == 0xFF) && (_shapeType != ShapeType.Shape1))
            {
                FillStyleCount = reader.ReadUInt16();
            }

            FillStyles = new List<FillStyleRecord>();

            for (int i = 0; i < FillStyleCount; i++ )
            {
                FillStyleRecord rec = new FillStyleRecord(_shapeType);
                rec.SwfDeserialize(reader);
                FillStyles.Add(rec);
            }
        }

        public void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IList<FillStyleRecord> Members

        public int IndexOf(FillStyleRecord item)
        {
            return FillStyles.IndexOf(item);
        }

        public void Insert(int index, FillStyleRecord item)
        {
            throw new NotImplementedException();
        }

        public void RemoveAt(int index)
        {
            throw new NotImplementedException();
        }

        public FillStyleRecord this[int index]
        {
            get
            {
                return FillStyles[index];
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion

        #region ICollection<FillStyleRecord> Members

        public void Add(FillStyleRecord item)
        {
            throw new NotImplementedException();
        }

        public void Clear()
        {
            throw new NotImplementedException();
        }

        public bool Contains(FillStyleRecord item)
        {
            return FillStyles.Contains(item);
        }

        public void CopyTo(FillStyleRecord[] array, int arrayIndex)
        {
            FillStyles.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return FillStyleCount; }
        }

        public bool IsReadOnly
        {
            get { return true; }
        }

        public bool Remove(FillStyleRecord item)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IEnumerable<FillStyleRecord> Members

        public IEnumerator<FillStyleRecord> GetEnumerator()
        {
            return FillStyles.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            IEnumerable temp = FillStyles;
            return temp.GetEnumerator();
        }

        #endregion

        #region IList Members

        int IList.Add(object value)
        {
            throw new NotImplementedException();
        }

        void IList.Clear()
        {
            throw new NotImplementedException();
        }

        bool IList.Contains(object value)
        {
            return Contains((FillStyleRecord)value);
        }

        int IList.IndexOf(object value)
        {
            return IndexOf((FillStyleRecord)value);
        }

        void IList.Insert(int index, object value)
        {
            throw new NotImplementedException();
        }

        bool IList.IsFixedSize
        {
            get { return true; }
        }

        bool IList.IsReadOnly
        {
            get { return true; }
        }

        void IList.Remove(object value)
        {
            throw new NotImplementedException();
        }

        void IList.RemoveAt(int index)
        {
            throw new NotImplementedException();
        }

        object IList.this[int index]
        {
            get
            {
                return FillStyles[index];
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion

        #region ICollection Members

        void ICollection.CopyTo(Array array, int index)
        {
            CopyTo((FillStyleRecord[])array,index);
        }

        int ICollection.Count
        {
            get { return Count; }
        }

        bool ICollection.IsSynchronized
        {
            get { return false; }
        }

        object ICollection.SyncRoot
        {
            get { throw new NotImplementedException(); }
        }

        #endregion
    }

     
}
